import Vue from 'vue'

const state = {
    source: false, // 是否是其他平台嵌入
    topBarHide: false, // 顶部导航隐藏状态
    asideHide: false, // 侧边栏隐藏状态
    pageConfig: {
        logo: '',
        name: '',
        headerVisible: true,
    },
    systemInfo: {}, // 当前选择系统信息
}

const mutations = {
    setSource(cState, payload) {
        cState.source = payload
    },
    setTopBarHide(cState, payload) {
        cState.topBarHide = payload
    },
    setAsideHide(visibleState, payload) {
        visibleState.asideHide = payload
    },
    setPageConfig(cState, payload) {
        cState.pageConfig = payload
    },
    'global/systemInfo': function setSystemInfo(global, payload) {
        global.systemInfo = payload
    },
}

const actions = {
    async getPageConfig({ commit }) {
        try {
            const { data } = await Vue.http.get('/api/monitor_warning/manage/getReportConf')
            if (data.code !== 0) {
                return
            }
            const config = {
                logo: data.data.logo,
                name: data.data.platform_name,
                headerVisible: data.data.is_show_header
            }
            commit('setPageConfig', config)
        } catch (error) {
            // eslint-disable-next-line no-console
            console.log(error)
        }
    },
}

export default {
    state,
    mutations,
    actions
}
